<?php
global $wpdb, $current_user, $user_ID;


$curUserId = get_current_user_id();
$mottakerlisten = $wpdb->get_results("
            SELECT DISTINCT b.bruker AS id
            FROM
            (
                SELECT senderid AS bruker, datom
                FROM meldinger
                WHERE mottakerid = '$curUserId'

                UNION

                SELECT mottakerid AS bruker, datom
                FROM meldinger
                WHERE senderid = '$curUserId'
            ) AS b
            ORDER BY datom DESC", ARRAY_A);
?>

<div style="float:left">   
    <?php
    foreach ($mottakerlisten as $mottaker) :

        $motid = $mottaker['id'];
        $userbutton = get_user_by('id', $motid);
        $tempid = $userbutton->id;
        ?>
        <jquery-form formmethod='post'>
            <input type="submit" onclick="js_vis_melding_liste(<?php echo $tempid; ?>)" value="<?php echo $userbutton->first_name . ' ' . $userbutton->last_name; ?>"/><br/>
        </jquery-form>

    <?php endforeach; ?>
</div>